/*
 * ProgressStatusSubscriber.h
 *
 *  Created on: Dec 25, 2014
 *      Authors: Avihay Avitan & Stefan Farcas
 */

#ifndef PROGRESSSTATUSSUBSCRIBER_H_
#define PROGRESSSTATUSSUBSCRIBER_H_
#include "../ProgressStatusConnection/ProgressStatusConnection.h"
#include "../ProgressStatus/ProgressStatus.h"
#include <queue>
#include <boost/thread.hpp>
#include <mutex>

using namespace std;

namespace ProgressStatusSpace {
/**
 * ProgressStatusSubscriber - provides the mechanism to initiate a connection and receiving the progress status
 */
class ProgressStatusSubscriber {
public:
	ProgressStatusSubscriber();
	virtual ~ProgressStatusSubscriber();
	bool receiveProgressStatus(ProgressStatus* received);

private:
	void consumerWorker();
	bool convertMessageToProgressStatus(ProgressMessage* received , ProgressStatus* status);
	ProgressStatusConnection consumer;
	mutex m;
	queue<ProgressMessage *> statusq;
	boost::thread * workerThread;
};

} /* namespace ProgressStatusSpace */

#endif /* PROGRESSSTATUSSUBSCRIBER_H_ */
